package cn.tedu.online.day02;

import java.util.Iterator;

public class StringDemo {
    public static void main(String[] args) {
        String string = "AAAAAABBBCCCCCDDDBDDDD";
        char[] chars = string.toCharArray();
        StringBuilder builder = new StringBuilder();
        int count = 1;

        for (int i= 0;i<chars.length-1;i++ ){
            if (chars[i]==chars[i+1]){
                count++;
            }else{
                builder.append(chars[i-1]).append(count);
                count = 1;
            }
        }
        builder.append(chars[chars.length-1]).append(count);

        System.out.println(builder);

    }

}
